package com.guang.syncronized.review_day1;

import org.openjdk.jol.info.ClassLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author liguang
 * @Date 2022/10/22/18:26
 */
public class SyncronziedBias_One {
    private final static Logger logger = LoggerFactory.getLogger(SyncronziedBias_One.class);
    public static void main(String[] args) throws InterruptedException {
        // 为什么让当前的锁对象为无锁可偏向
        TimeUnit.SECONDS.sleep(5);
        Object object = new Object();
        logger.info("直接启动的时候，当前对象的对象头中是101,无锁可偏向。打印对象头：{}", ClassLayout.parseInstance(object).toPrintable());
        logger.info("进入到同步代码块中来");
        synchronized (object){
            logger.info("直接启动的时候，当前对象的对象头中是101,有锁可偏向。打印对象头：{}", ClassLayout.parseInstance(object).toPrintable());
        }
    }
}
